-- @owner: @zhanghuan96
-- @date: 2024/9/18
-- @testpoint: rownum作为触发器名
@conn PrimaryDbDmode;
--step1:建表;expect:成功
drop table if exists t_rownum_0009;
drop table if exists t_rownum_0009_1;
create table t_rownum_0009(id1 int, id2 int, id3 int);
create table t_rownum_0009_1(id1 int, id2 int, id3 int);

--step2:创建触发器函数;expect:成功
drop function if exists f_rownum_0009;
create or replace function f_rownum_0009() returns trigger
leakproof as
$$
declare
begin
insert into t_rownum_0009_1 values(new.id1, new.id2, new.id3);
return new;
end;
$$ language plpgsql;
/
--step3:创建触发器使用rownum作为触发器名;expect:成功
drop trigger if exists rownum on t_rownum_0009;
create trigger rownum before insert on t_rownum_0009
for each row
execute procedure f_rownum_0009();
/
insert into t_rownum_0009 values(100,200,300);
select * from t_rownum_0009;
select * from t_rownum_0009_1;
select pg_get_functiondef('f_rownum_0009'::regproc::oid);

--step4:清理环境;expect:成功
drop trigger if exists rownum on t_rownum_0009;
drop function if exists f_rownum_0009;
drop table if exists t_rownum_0009;
drop table if exists t_rownum_0009_1;
